<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>选择员工</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="${ctx}/static/css/style.css" type="text/css" /> 
<link rel="stylesheet" href="${ctx}/static/css/style1.css" type="text/css" /> 
<link rel="stylesheet" href="${ctx}/static/css/kongjian.css" type="text/css" /> 
<script src="${ctx}/static/script/jquery-1.4.min.js" type="text/javascript"></script>
<script src="${ctx}/static/script/jquery.form.js" type="text/javascript"></script>
	<script>
		function select(id,name){
			window.returnValue=[id,name];
			window.close();
		}
		
		$(document).ready(function(){
		
		Date.prototype.pattern=function(fmt) {        
    var o = {        
    "M+" : this.getMonth()+1, //月份        
    "d+" : this.getDate(), //日        
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时        
    "H+" : this.getHours(), //小时        
    "m+" : this.getMinutes(), //分        
    "s+" : this.getSeconds(), //秒        
    "q+" : Math.floor((this.getMonth()+3)/3), //季度        
    "S" : this.getMilliseconds() //毫秒        
    };        
    var week = {        
    "0" : "\u65e5",        
    "1" : "\u4e00",        
    "2" : "\u4e8c",        
    "3" : "\u4e09",        
    "4" : "\u56db",        
    "5" : "\u4e94",        
    "6" : "\u516d"     
    };        
    if(/(y+)/.test(fmt)){        
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));        
    }        
    if(/(E+)/.test(fmt)){        
            fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);        
    }        
    for(var k in o){        
            if(new RegExp("("+ k +")").test(fmt)){        
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));        
            }        
    }        
    return fmt;        
}
			$.get('${ctx}/account/user/getDepList', function(data) {
				$("#departmentId").append("<option>全部</option>");
				for(var i=0;i<data.length;i++){
					var id=data[i].id;
					var name=data[i].name;
					$("#departmentId").append("<option value='"+id+"'>"+name+"</option>"); 
				}
			  
			}); 
			
		  $('#queryForm').each(function() {
	        $('input').keypress(function(e) {
	            if(e.which == 10 || e.which == 13) {
	                refresh();
	            }
	        });
	    });
		  
		  
		  	
		  $("#queryButton").click(function(){
		  	refresh();
		  });
		});
		
		function refresh(){
			$(".ggkj_tdColr").remove();
			$('#queryForm').ajaxSubmit(function(data) {
		  		for(var i=0;i<data.length;i++){
		  			var gender="男";
		  			if(data[i].gender=="1"){
		  				gender="女";
		  			}
		  			var tel="";
		  			if(data[i].tel!=null){
		  				tel=data[i].tel;
		  			}
		  			var d=new Date(data[i].createDate);
		  			var createDate=d.pattern("yyyy-MM-dd");
		  			var status="在职";
		  			if(data[i].status=="9"){
		  				status="离职";
		  			}
		  			$("#content").append("<tr class='ggkj_tdColr'><td>"+data[i].staffCode+"</td><td><a href='#' onclick=select('"+data[i].id+"','"+data[i].name+"')>"+data[i].name+"</a></td><td>"+data[i].department.name+"</td><td>"+tel+"</td><td>"+gender+"</td><td></td><td>"+createDate+"</td><td>"+status+"</td></tr>");
		  		} 
		  	});
		} 
	</script>
</head>

<body>
<div class="er_banner">选择员工</div>
<div class="shenqing2">
	<form:form id="queryForm"  modelAttribute="selectStaffForm" action="${ctx}/account/user/ajaxSelect">
		<table width="100%" border="0" cellspacing="0" cellpadding="0" >
	      <tr>
	        <td width="61">员工姓名：</td>
	        <td width="150px" style="color:#2E74D1;"><input type="text" name="staffName" class="ggkj_inputtext_80" value="${selectStaffForm.staffName}" /></td>
	        <td width="85">员工编号：</td>
	        <td width="150px" style="color:#2E74D1;"><input type="text" name="staffCode" class="ggkj_inputtext_80" value="${selectStaffForm.staffCode}" />
	        </td>
			<td width="85">所在部门：</td>
	        <td width="150px" style="color:#2E74D1;">
	        	<select id="departmentId" name="departmentId" class="u83">
	        		
	        	</select>
				 
	        </td>
	        </td>
			 <td width="93"><input id="queryButton" name="Input" type="button" class="chaxun_btn" value="&nbsp;&nbsp;查询" />
	         </td>
	      </tr>
		</table>
	</form:form>
</div>

<div class="yiban">
	<table id="content" style="width:100%;" class="ggkj_table"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col">员工编号</th>
    <th scope="col">员工姓名</th>
    <th scope="col">所在部门</th>
    <th scope="col">电话</th>
    <th scope="col">性别</th>
    <th scope="col">上级领导</th>
    <th scope="col">入职日期</th>
    <th scope="col">状态</th>
  </tr>
  
  <c:forEach items="${staffList}" var="item">
	  <tr class="ggkj_tdColr">
	    <td>${item.staffCode}</td>
	    <td><a href="#" onclick="select('${item.id}','${item.name}')">${item.name}</a></td>
	    <td>${item.department.name}</td>
	    <td>${item.tel}</td>
	    <td><c:if test="${item.gender==0}">男</c:if><c:if test="${item.gender==1}">女</c:if></td>
	    <td></td>
	    <td><fmt:formatDate value="${item.createDate}"/></td>
	    <td><c:if test="${item.status==1}">在职</c:if><c:if test="${item.status==9}">离职</c:if></td>
	  </tr>
	</c:forEach>
</table>
	
</div>
 
</body>
</html>
